
<template>
  <div id="app">
    <div>
      <span>姓名:</span>
      <input type="text" v-model="name"/>
    </div>
    <div>
      <span>年龄:</span>
      <input type="number" v-model.number="age"/>
    </div>
    <div>
      <span>性别:</span>
      <select v-model=num>
        <option value="男">男</option>
        <option value="女">女</option>
      </select>
    </div>
    <div>
      <button @click.prevent="tian">添加/修改</button>
    </div>
    <div>
      <table
        border="1"
        cellpadding="10"
        cellspacing="0"
      >
        <tr>
          <th>序号</th>
          <th>姓名</th>
          <th>年龄</th>
          <th>性别</th>
          <th>操作</th>
        </tr>
        <tr v-for="(ele,i) in arr" :key="i">
          <td>{{i+1}}</td>
          <td>{{ele.name}}</td>
          <td>{{ele.age}}</td>
          <td>{{ele.sex}}</td>
          <td>
            <button @click.prevent="san(i)">删除</button>
            <button >编辑</button>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
export default {
data(){
return {
 
  name:'',
  age:'',
   arr:[
  {
  name:'小狗',
  age:10,
  sex:'男',
},
  {
 
  name:'小狗',
  age:10,
  sex:'男',
},
  {

  name:'小狗',
  age:10,
  sex:'男',
},
],
num:[]
}
},
methods:{
  tian(){
    if(this.name.trim().length===0||this.age<=0){
      return alert('输入点内容行不行')
    }
    this.arr.unshift({
      name:this.name,
      age:this.age,
      sex:this.num[0]
    })
  },
  san(i){
  this.arr=this.arr.push()
  }
}
}
</script>
